package com.File;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class ObjectInputStream_ {
    public static void main(String[] args) throws ClassNotFoundException {
        //指定反序列化文件
        String filePath = "d:\\date.dat";
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filePath));
            //读取的时候要和序列化的顺序相同
            System.out.println(ois.readInt());
            System.out.println(ois.readBoolean());
            System.out.println(ois.readChar());
            System.out.println(ois.readUTF());
            Object o = ois.readObject();
            System.out.println("运行类型:" + o.getClass());
            System.out.println("相关信息:" + o);//底层 Object->Dog
            //关闭流,关闭外层流即可,底层会关闭FileInputStream流
            ois.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
